package com.jsgt.greekfire.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import java.util.List;

/***
 * IDialog 基本实现
 */
public class DialogImpl extends IDialog {

    public Dialog showItemDialog(Context context, String title,
                                 List<String> items, List<Integer> icons, final DialogCallBack dialogCallBack) {
        int gravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
        return showItemDialog(context, title, items, icons,gravity, gravity, dialogCallBack);
    }

    public Dialog showItemDialog(Context context, String title,
                                 List<String> items, List<Integer> icons,int itemGravity, int titleGravity, final DialogCallBack dialogCallBack) {
        final MenuDialog dialog = new MenuDialog(context, items, icons,title, itemGravity, titleGravity);
        dialog.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                dialog.dismiss();
                if (dialogCallBack != null) {
                    dialogCallBack.onClick(position);
                }
            }
        });
        dialog.show();
        return dialog;

    }


}
